from multiprocessing import Process
from time import sleep

'''
进程
from multiprocessing import Process

process = Process(target = 函数 , name = 进程名称 , args = (给函数的参数))

process.run() 只是执行任务 并不会启动进程
process.start() 启动进程 并且开始执行任务 
process.terminate() 终止
'''


def task1(arg, name):
    while True:
        sleep(arg)
        print(name)


def task2(arg, name):
    while True:
        sleep(arg)
        print(name)


number = 0

if __name__ == '__main__':
    # 创建进程 run 只是执行 start
    p1 = Process(target=task1, name="进程1", args=(1, "任务1"))
    p1.start()
    print(p1.name)

    p2 = Process(target=task2, name="进程2", args=(1, "任务2"))
    p2.start()
    print(p2.name)

    while True:
        number += 1
        sleep(1)
        if number > 10:
            p1.terminate()
            p2.terminate()
            break
        else:
            print("number->{}".format(number))

    print("********************")
